/**
 * Created by pello  on 2016/11/25.
 * 创建 wtmapSetLocation 用户设置位置指令
 */
app.controller("wtmapSetLocationController",["$rootScope","$scope","wtmapService","$timeout","toaster",function($rootScope,$scope,wtmapService,$timeout,toaster){
//初始化地图指令
$scope.mapIntialed=function(option){var promise=wtmapService.intialMap(option.mapid,!1,0,$rootScope.arcgisConfig.lods);//同步调用，获取承诺接口
promise.then(function(mapobj){$scope.mapcadObj=mapobj,$scope.mapcadObj.addDynamicMap($rootScope.arcgisConfig.baseMap),$scope.loadLayer($scope.option.layers),$scope.mapcadObj.zoomTobyXY(option.center.x,option.center.y,option.zoom)},function(data){})},
//获取中心点坐标
//格式：{"type":"point","x":155307.451,"y":139762.144,"spatialReference":{"wkid":102100,"latestWkid":3857}}
$scope.getCenter=function(){
// console.log("$scope.mapcadObj" ,new Date(),mapobj,$scope.mapcadObj);
return $scope.mapcadObj.appMap.extent.getCenter()},/**
         * 设置多点定位
         * @param points eg:[{x:0,y:2},{x:0,y:2}]
         */
$scope.setLocation=function(points){if(points){0===points.length&&toaster.pop("warning","提示","未找到定位点！");var _timeout=$timeout(function(){$scope.mapcadObj?($scope.mapcadObj.setMapExtendByPoints(points,3,$rootScope.centerOptions),$timeout.cancel(_timeout)):$timeout(function(){$scope.setLocation(points)},500)},500)}},/**
         * loadLayer  加载图层
         * @param layers [{layerName:"",layerFilter:""}] 图层名称
         */
$scope.loadLayer=function(layers){if($scope.mapcadObj)$timeout.cancel(_timeout);else var _timeout=$timeout($scope.loadLayer(layers),500);
// const LAYERS = $rootScope.arcgisConfig.layerInfosObj;//总图层配置
// var cur_layers = layerNames;// 要添加图层的信息
var featurefayers=[];return layers&&layers.length>0?(layers.forEach(function(item,index){var featurelayer=$scope.mapcadObj.addFeatureLayer(item.layerName,{maxScale:0,minScale:0,showInfoTemplate:!1,definitionExpression:item.layerFilter});featurefayers.push({layerName:item,featurelayer:featurelayer})}),featurefayers):void console.log("没有添加设施图层")}}]),app.directive("wtmapSetLocation",function(){return{restrict:"EA",replace:!0,template:'<div><wt-map mapid="{{ option.mapid }}" height="option.height" showgdmap="option.showgdmap" map-intialed="mapIntialed(option)"></wt-map></div>',scope:{option:"=",position:"="},controller:"wtmapSetLocationController",
//require : "wtmapSetLocationController",
link:function(scope,element,attrs,controller){var defaltOption={mapid:"setLoction",center:{x:155307.451,y:139762.144,lng:0,lat:0},zoom:1,height:700,showgdmap:!1,layerNames:["设备点"]};scope.option?scope.option=_.extend(defaltOption,scope.option):
//设置默认参数
scope.option=defaltOption,
//监视position定位点的变化
scope.$watch("position",function(oldValue,newValue){scope.setLocation(scope.position)}),scope.setLocation(scope.position)}}});